package cn.sumpu.app.coolsk.domain;

import java.io.*;
import java.util.*;

public class Channel implements Serializable {

	private static final long serialVersionUID = 6060243575149682673L;
	
	private String id;
	private String mark;
	private String name;
	private String parent;
	private Integer deep;
	private Integer type;
	private Date gmtCreated;
	private Date gmtModified;
	//父频道
	private Channel channel;
	
	private List<Channel> channelList = new ArrayList<Channel>();
	public static String treeJson = "";
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getMark() {
		return mark;
	}
	public void setMark(String mark) {
		this.mark = mark;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getParent() {
		return parent;
	}
	public void setParent(String parent) {
		this.parent = parent;
	}
	public Integer getDeep() {
		return deep;
	}
	public void setDeep(Integer deep) {
		this.deep = deep;
	}
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	public Date getGmtCreated() {
		return gmtCreated;
	}
	public void setGmtCreated(Date gmtCreated) {
		this.gmtCreated = gmtCreated;
	}
	public Date getGmtModified() {
		return gmtModified;
	}
	public void setGmtModified(Date gmtModified) {
		this.gmtModified = gmtModified;
	}
	public List<Channel> getChannelList() {
		return channelList;
	}
	public void setChannelList(List<Channel> channelList) {
		this.channelList = channelList;
	}
	public Channel getChannel() {
		return channel;
	}
	public void setChannel(Channel channel) {
		this.channel = channel;
	}
	//构建树
	public static String buildChannelTree(List<Channel> channelList){
		Channel c = new Channel();
		for(int i=0; i<channelList.size(); i++){
			c = channelList.get(i);
			treeJson += "{\"text\": \""+c.getName()+"\",\"id\":\""+c.getId()+"\""+",\"mark\":\""+c.getMark()+"\"";
			if(c.getChannelList()==null || c.getChannelList().size()==0){
				treeJson += ",\"url\":\"/misc/cms/toBackContent.htm?channelId="+c.getMark()+"\"";
			}
			if(c.getChannelList()!=null && c.getChannelList().size()>0){
				treeJson += ",\"isexpand\": false ,\"children\": [";
				buildChannelTree(c.getChannelList());
				treeJson += "]";
			}
			treeJson += "}";
			if((i+1) < channelList.size()){
				treeJson += ",";
			}
		}
		return treeJson;
	}
	public static String getChannelTree(List<Channel> channelList){
		treeJson = "[";
		String tree = buildChannelTree(channelList);
		tree += "]";
		return tree;
	}
	
}
